<template lang="pug">
  div
    s-table(
      ref="table"
      v-loading="loading"
      reqUrl="/peapi/evaluate/children_reports"
      :column="classesColumn"
      :filterProps="{fields: searchConfig}"
      :queryPropsParams="{areaId: curArea.areaId}"
    )
      template(slot="created" slot-scope="text, scope")
        span {{text | dateFilter('YYYY/MM/DD hh:mm:ss')}}
      template(slot="action" slot-scope="text, scope")
        template
          el-link(slot="reference" v-if="!scope.cardNo" type="primary" @click="actionHandle(scope, 'export')") 导出报告
</template>
<script>
import { mapGetters } from 'vuex'
import { column } from './config'
import { getClassesByArea } from '@/api/common'
import { evaluateExport } from '../api'
export default {
  components: {
  },
  data () {
    return {
      classesColumn: column,

      classes: [],
      classId: '',

      loading: false
    }
  },
  computed: {
    ...mapGetters(['curArea']),
    searchConfig () {
      return [
        {
          label: '选择班级',
          key: 'classesId',
          type: 'select',
          fieldProps: {
            options: this.classes,
            props: { value: 'id', label: 'name' }
          }
        },
        {
          key: 'childName',
          label: '宝宝姓名'
        }
      ]
    }
  },
  created () {
    this.getClasses()
  },
  methods: {
    refreshTable (flag = false) {
      this.$refs.table.refresh(flag)
    },

    // 获取托班班级列表
    async getClasses () {
      const { curArea } = this
      this.classes = await (getClassesByArea({ areaId: curArea.areaId }) || [])
      this.classId = this.classes[0]?.id || ''
    },

    actionHandle (row, type = 'unbind') {
      console.log(type)
      if (type === 'export') {
        const params = {
          reportId: row.id,
          exportType: 'pdf'
        }
        evaluateExport(params).then(res => {
          window.location.href = res
        })
      }
    }
  }
}
</script>
<style lang="scss" scoped>
.video{
  width: 100%;
  height: 560px
}
.close{
  margin-top: 20px;
}
</style>
